<?php
/**
 * Created by PhpStorm.
 * User: coolinmind
 * Date: 21/01/2019
 * Time: 16:20
 */

namespace App\Modules\UCenter;


use App\Services\UCenter\UCenterIndex;

class Company extends BaseUcenter
{
    public function companyAuthentication()
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        return UCenterIndex::Company()->companyAuthentication($data);
    }

    //发送邀约
    public function sendInvite(){
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        return UCenterIndex::Company()->sendInvite($data);
    }

    //邀约列表
    public function inviteList(){
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        return UCenterIndex::Company()->inviteList($data);
    }

    /**
     * 车主添加车辆
     * @return array
     */
    public function addCars()
    {
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        return UCenterIndex::Company()->addCars($data);
    }

    //司机与车辆进行绑定
    public function driverAndCar(){
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['company_id'] = $userInfo['res']['id'];
        return UCenterIndex::Company()->driverAndCar($data);
    }

    //司机与车辆进行绑定
    public function removeDriverAndCar(){
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        return UCenterIndex::Company()->removeDriverAndCar($data);
    }

    //通过姓名或手机号查找公司下的员工
    public function companyDriverByRea(){
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['company_id'] = $userInfo['res']['id'];
        return UCenterIndex::Company()->companyDriverByRea($data);
    }

    //同意邀约
    public function agreeInvite(){
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        return UCenterIndex::Company()->agreeInvite($data);
    }

    //查看车辆下的司机
    public function carHasDriver(){
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        return UCenterIndex::Company()->carHasDriver($data);
    }

    //车辆移除
    public function removeCompanyCar(){
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        return UCenterIndex::Company()->removeCompanyCar($data);
    }

    //车辆审核列表
    public function carCheckList(){
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        return UCenterIndex::Company()->carCheckList($data);
    }

    //司机管理
    public function driverManage(){
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['company_id'] = $userInfo['res']['id'];
        return UCenterIndex::Company()->driverManage($data);
    }

    //公司司机解绑
    public function companyDriverUnbind(){
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        return UCenterIndex::Company()->companyDriverUnbind($data);
    }

    //拒绝邀约
    public function refuseInvite(){
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        return UCenterIndex::Company()->refuseInvite($data);
    }

    //运输管理
    public function wayBillManage(){
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        return UCenterIndex::Company()->wayBillManage($data);
    }

    //获取配置信息
    public function getSetting(){
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        return UCenterIndex::Company()->getSetting($data);
    }

    //委托申请数量
    public function entrustCount(){
        $userInfo = $this->isLogin();
        if ($userInfo['status'] !== SUCCESS_STATUS) {
            return need_login($userInfo,'请登录');
        }
        $data = $this->postData;
        $data['user_id'] = $userInfo['res']['id'];
        return UCenterIndex::Company()->entrustCount($data);
    }
}
